package net.bsayiner.phoneTest;

import java.util.ArrayList;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class GridviewAdapter extends BaseAdapter {

	private Activity activity;
	private ArrayList<String> listTestNames;
	private ArrayList<Integer> listTestIcons;

	public GridviewAdapter(Activity activity, ArrayList<String> listTestNames, ArrayList<Integer> listTestIcons) {
		this.activity = activity;
		this.listTestNames = listTestNames;
		this.listTestIcons = listTestIcons;
	}

	public int getCount() {
		return listTestNames.size();
	}

	public String getItem(int position) {
		return this.listTestNames.get(position);
	}

	public long getItemId(int position) {
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder view;
		LayoutInflater inflator = activity.getLayoutInflater();

		if (convertView == null) {
			view = new ViewHolder();
			convertView = inflator.inflate(R.layout.gridview_row, null);

			view.testName = (TextView) convertView.findViewById(R.id.txtTestName);
			view.testIcon = (ImageView) convertView.findViewById(R.id.txtTestIcon);

			convertView.setTag(view);
		} else {
			view = (ViewHolder) convertView.getTag();
		}

		view.testName.setText(listTestNames.get(position));
		view.testIcon.setImageResource(listTestIcons.get(position));

		return convertView;
	}

	public static class ViewHolder {
		public TextView testName;
		public ImageView testIcon;
	}

}
